package com.liuyk.commonlib.update;

import android.content.Context;
import android.text.TextUtils;

import com.liuyk.commonlib.dialog.BaseDialog;

/**
 * 更新弹窗
 * <p>
 * Created by liuyakui on 2020/7/2
 */
public class UpdateDialogUtils {

    public static Builder builder(Context context) {
        return new Builder(context);
    }

    public static class Builder {
        private UpdateDialog mUpdateDialog;

        public Builder(Context context) {
            mUpdateDialog = new UpdateDialog(context);
        }

        public Builder setUpdateIcon(int resId) {
            if (resId != -1) {
                mUpdateDialog.getUpdateIcon().setImageResource(resId);
            }
            return this;
        }

        public Builder setUpdateIconVisibility(int visibility) {
            mUpdateDialog.getUpdateIcon().setVisibility(visibility);
            return this;
        }

        public Builder setTitle(String title) {
            if (!TextUtils.isEmpty(title)) {
                mUpdateDialog.getTitleText().setText(title);
            }
            return this;
        }

        public Builder setTitleVisibility(int visibility) {
            mUpdateDialog.getTitleText().setVisibility(visibility);
            return this;
        }

        public Builder setLeftText(String leftText) {
            if (!TextUtils.isEmpty(leftText)) {
                mUpdateDialog.getLeftText().setText(leftText);
            }
            return this;
        }

        public Builder setLeftBtnTextColor(int leftTextColor) {
            if (leftTextColor != -1) {
                mUpdateDialog.getLeftText().setTextColor(leftTextColor);
            }
            return this;
        }

        public Builder setLeftBtnVisibility(int visibility) {
            mUpdateDialog.getLeftText().setVisibility(visibility);
            return this;
        }

        public Builder setRightText(String rightText) {
            if (!TextUtils.isEmpty(rightText)) {
                mUpdateDialog.getRightText().setText(rightText);
            }
            return this;
        }

        public Builder setRightBtnTextColor(int rightTextColor) {
            if (rightTextColor != -1) {
                mUpdateDialog.getRightText().setTextColor(rightTextColor);
            }
            return this;
        }

        public Builder setRightBtnVisibility(int visibility) {
            mUpdateDialog.getRightText().setVisibility(visibility);
            return this;
        }

        public Builder setContentText(String contentText) {
            if (!TextUtils.isEmpty(contentText)) {
                mUpdateDialog.getContentText().setText(contentText);
            }
            return this;
        }

        public Builder setContentTextColor(int contentTextColor) {
            if (contentTextColor != -1) {
                mUpdateDialog.getContentText().setTextColor(contentTextColor);
            }
            return this;
        }

        public Builder setContentVisibility(int visibility) {
            mUpdateDialog.getContentText().setVisibility(visibility);
            return this;
        }

        public Builder setNeutralClickListener(BaseDialog.NeutralClickListener neutralClickListener) {
            if (neutralClickListener != null) {
                mUpdateDialog.setNeutralClickListener(neutralClickListener);
            }
            return this;
        }

        public Builder setPositiveClickListener(BaseDialog.PositiveClickListener positiveClickListener) {
            if (positiveClickListener != null) {
                mUpdateDialog.setPositiveClickListener(positiveClickListener);
            }
            return this;
        }

        public void show(String apkUrl, String desc, String versionName, boolean isForce) {
            mUpdateDialog.setData(apkUrl, desc, versionName, isForce);
            mUpdateDialog.show();
        }
    }
}
